<?php 
    namespace Media\Component;
    use DateTime;
    use Media\Component\AbstractComponent;
    
    class PhotoComponent extends AbstractComponent {
        protected  $entity="Media\\Entity\\Photo";
        
        
        function insert($object){
            $now = new DateTime("now");
            $object->created_at = $now;
            $object->modified_at = $now;
            $this->em->persist($object);
            $this->em->flush();
        }
        
        
        function update($object){
            $now = new DateTime("now");
            $object->modified_at = $now;
            $this->em->persist($object);
            $this->em->flush();
        }
        
        
        function delete($id){
            $user = $this->em->find($this->entity, $id);
            $this->em->remove($user);
            $this->em->flush();
        }
        
        
        function get($id){
            return $this->em->find($this->entity, $id);
        }
        
        
        function listAll(){
            return $this->em->getRepository($this->entity)->findAll();
        }
        
        public function listLimit($albumId, $number=null){
        	return $this->em->getRepository($this->entity)->listLimit($albumId, $number);
        }
        
        
        public function listFromMin($minId, $maxResult=null, $excludeMin=true){
            return $this->em->getRepository($this->entity)->listFromMin($minId, $maxResult, $excludeMin);
        }
        
        
        public function listFromMax($maxId, $maxResult=null, $excludeMax=true){
            return $this->em->getRepository($this->entity)->listFromMax($maxId, $maxResult, $excludeMax);
        }
        
        
        public function listFromMinInAlbum($albumId, $minId, $maxResult=null, $excludeMin=true){
            return $this->em->getRepository($this->entity)->listFromMinInAlbum($albumId, $minId, $maxResult, $excludeMin);
        }
        
        
        public function listFromMaxInAlbum($albumId, $maxId, $maxResult=null, $excludeMax=true){
            return $this->em->getRepository($this->entity)->listFromMaxInAlbum($albumId, $maxId, $maxResult, $excludeMax);
        }
        
        
        public function listByProvider($idProvider, $maxResult=null){
            return $this->em->getRepository($this->entity)->listByProvider($idProvider, $maxResult);
        }
        
        
        public function listByFilter($idFilter, $maxResult=null){
            return $this->em->getRepository($this->entity)->listByFilter($idFilter, $maxResult);
        }
        
        
        public function listByUser($idUser, $maxResult=null){
            return $this->em->getRepository($this->entity)->listByUser($idUser, $maxResult);
        }
        
        
        public function listByAlbum($idAlbum, $maxResult=null){
            return $this->em->getRepository($this->entity)->listByAlbum($idAlbum, $maxResult);
        }
        
        public function countByAlbum($albumId){
            return $this->em->getRepository($this->entity)->countByAlbum($albumId);
        }
        
        
    }
